/*	This program produces Table D.6 */

***** Set directories 
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/ech_clean.dta", clear

local listcontrols1 = " i.t " 
local listcontrols2 = " i.t i.fsize i.ciiu2 " 
local listcontrols3 = " i.t i.fsize i.ciiu2  i.year#i.fsize i.year#i.ciiu2   " 


** Panel A
estimates clear
foreach y in "Wz" "hoursz" {
	foreach c in  1 2 3 {
		preserve
		keep if empl==1 & small==1
		*Normalize wages
		sum W if age_centered==-1
		local meanw=r(mean)
		g Wz=W/`meanw'
		*Normalize hours
		sum hours if age_centered==-1
		local meanh=r(mean)
		g hoursz=hours/`meanh'
		* Create sample
		reghdfe `y' pre48 post5053 post54 [aw=weight], absorb(`listcontrols3') 
		g thissample=e(sample)
		* Regress
		eststo: reghdfe `y' pre48 post5053 post54 if thissample==1 [aw=weight], absorb(`listcontrols`c'') vce(robust)
		restore
	}
}
esttab using "`dir_output'/TableD6a.tex", ///
	keep(pre* post* )  noobs sfmt(%9.0f) ///
	b(%4.3f) se(%4.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	f nomtitles  nogaps replace label nonumbers nolines
	
** Panel B
estimates clear
foreach y in "Wz" "hoursz" {
	foreach c in  1 2 3 {
		preserve
		keep if empl==1 & small==1
		*Normalize wages
		sum W if age_centered==-1
		local meanw=r(mean)
		g Wz=W/`meanw'
		*Normalize hours
		sum hours if age_centered==-1
		local meanh=r(mean)
		g hoursz=hours/`meanh'
		* Create sample
		reghdfe `y' aget post50 aget_post50  [aw=weight], absorb(`listcontrols3') 
		g thissample=e(sample)
		* Regress
		eststo: reghdfe `y' aget post50 aget_post50 if thissample==1 [aw=weight], absorb(`listcontrols`c'') vce(robust)
		restore
	}
}
esttab using "`dir_output'/TableD6b.tex", ///
	keep(post* age*) stats(N, label("Observations") fmt(%9.0gc)) ///
	b(%4.3f) se(%4.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	f nomtitles  nogaps replace label nonumbers nolines prefoot(\hline) 

